package com.cskaoyan.controller;

import com.cskaoyan.bean.*;
import com.cskaoyan.service.GoodService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author WeitenHong
 * @date 2020/9/30 17:30
 */
@RestController
@RequestMapping("admin/goods")
public class GoodController {

    @Autowired
    GoodService goodService;

    @RequestMapping("/list")
    public BaseRespVo list(Integer page,Integer limit,String goodsSn,String name,String sort,String order){
       ListBean listBean=goodService.queryGoodListBean(page,limit,goodsSn,name,sort,order);
       return BaseRespVo.ok(listBean);
    }

    @RequestMapping("/detail")
    public BaseRespVo detail(Integer id){
        GoodVO goodVO=goodService.queryGoodDetail(id);
        return BaseRespVo.ok(goodVO);
    }

    @RequestMapping("/catAndBrand")
    public BaseRespVo catAndBrand(){
        BrandVO brandVO=goodService.queryBrand();
        return BaseRespVo.ok(brandVO);
    }

    @RequestMapping("/update")
    public BaseRespVo update(@RequestBody GoodVO goodVO){
        goodService.updateGood(goodVO);
        return BaseRespVo.ok();
    }

    @RequestMapping("/create")
    public BaseRespVo create(@RequestBody GoodVO goodVO){
        goodService.create(goodVO);
        return BaseRespVo.ok();
    }

    @RequestMapping("/delete")
    public BaseRespVo delete(@RequestBody Goods good){
        goodService.delete(good);
        return BaseRespVo.ok();
    }
}
